import {
	url
} from "uview-plus/libs/function/test";

export const paginate = (array, page_size, page_number) => {
	// 计算分页开始的索引
	const startIndex = (page_number - 1) * page_size;
	// 使用slice方法获取当前页的数据
	return array.slice(startIndex, startIndex + page_size);
}

export const jumpPage = (url, params) => {
	let p = url.startsWith("/") ? "/pages" : "/pages/";
	url = p + url + objectToQueryString(params);
	uni.navigateTo({
		url: url,
		complete: () => {
		}
	})
}



export const objectToQueryString = (obj = {}) => {
	let params = [];
	for (let key in obj) {
		if (typeof obj[key] === 'object') {
			for (let subKey in obj[key]) {
				params.push(encodeURIComponent(key + '.' + subKey) + '=' + encodeURIComponent(obj[key][subKey]));
			}
		} else {
			params.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
		}
	}
	return params.join('&');
}